/******************************************************************************
 * @File name   :      PackageRedemptionLinesDaoImpl.java
 *
 * @Author      :      ANMA
 *
 * @Date        :      Aug 3, 2015
 *
 * @Copyright Notice: 
 * Copyright (c) 2014 DMS, Inc. All  Rights Reserved.
 * This software is published under the terms of the DMS Software
 * License version 1.0, a copy of which has been included with this
 * distribution in the LICENSE.txt file.
 * 
 * ----------------------------------------------------------------------------
 * Date                         Who         Version         Comments
 * Aug 3, 2015 5:05:19 PM    ANMA      1.0            Initial Version
 *****************************************************************************/
package com.cap.bts.crmdp.dealer.activation.dao.impl;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;

import com.cap.bts.crmdp.dealer.activation.dao.IPackageRedemptionLinesDao;
import com.cap.bts.crmdp.dealer.activation.domain.PackageRedemptionLines;
import com.cap.bts.crmdp.dealer.activation.dto.ActivationQueryDto;
import com.cap.bts.framework.common.dao.impl.BaseDaoImpl;
import com.cap.bts.framework.common.exception.AppException;
import com.cap.bts.framework.common.util.Utils;

/**
 * 
 */
@Repository("packageRedemptionLinesDao")
public class PackageRedemptionLinesDaoImpl extends BaseDaoImpl<PackageRedemptionLines, Long>implements IPackageRedemptionLinesDao {

	
	@Inject
	public PackageRedemptionLinesDaoImpl(@Value("com.cap.bts.crmdp.dealer.activation.domain.PackageRedemptionLines") Class<PackageRedemptionLines> clazz) {
		super(clazz);
	}

	@Override
	public List<PackageRedemptionLines> getPackageRedemptionLinesByDto(ActivationQueryDto dto) throws AppException {
        StringBuilder hql = new StringBuilder();
        hql.append("select a from PackageRedemptionLines a where 1=1");

        //根据卡的定义ID找该卡对应的服务Lines
        if(Utils.notNullAndNegative(dto.getPackageDefId())){
        	hql.append(" and a.packageDefId=" + dto.getPackageDefId());
        }

        List<PackageRedemptionLines> linesList = super.getJpaTemplate().find(hql.toString());
        if(linesList != null && !linesList.isEmpty()){
        	return linesList;
        }
		return new ArrayList<PackageRedemptionLines>();
	}
}
